package com.bootdo.sell.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.sell.domain.ShowpageDO;
import com.bootdo.sell.service.ShowpageService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 商品展柜展示页表
 * 
 * @author mp
 * @email 1992lcg@163.com
 * @date 2020-03-02 09:22:07
 */
 
@Controller
@RequestMapping("/sell/showpage")
public class ShowpageController {
	@Autowired
	private ShowpageService showpageService;
	
	@GetMapping()
	@RequiresPermissions("sell:showpage:showpage")
	String Showpage(){
	    return "sell/showpage/showpage";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("sell:showpage:showpage")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ShowpageDO> showpageList = showpageService.list(query);
		int total = showpageService.count(query);
		PageUtils pageUtils = new PageUtils(showpageList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("sell:showpage:add")
	String add(){
	    return "sell/showpage/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("sell:showpage:edit")
	String edit(@PathVariable("id") Integer id,Model model){
		ShowpageDO showpage = showpageService.get(id);
		model.addAttribute("showpage", showpage);
	    return "sell/showpage/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("sell:showpage:add")
	public R save( ShowpageDO showpage){
		if(showpageService.save(showpage)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("sell:showpage:edit")
	public R update( ShowpageDO showpage){
		showpageService.update(showpage);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("sell:showpage:remove")
	public R remove( Integer id){
		if(showpageService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("sell:showpage:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		showpageService.batchRemove(ids);
		return R.ok();
	}
	
}
